
function Part(gl, value) {
	this.vertexBuffer = gl.createBuffer();
	this.normalBuffer = gl.createBuffer();
	this.colorsBuffer = gl.createBuffer();
	this.indexBuffer = gl.createBuffer();
	/* Position in 3D */
	this.x = 0.0;
	this.y = 0.0;
	this.z = 0.0;
	/* 3D orientation (amount of rotation around each of 3 axes) */
	this.rx = 0.0;
	this.ry = 0.0;
	this.rz = 0.0;
	/* physical mass */
	this.m = 1.0;
	/* size (for collisions) */
	this.s = 1.0;
	/* density */
	this.dn = 1.0;
	/* friction */
	this.fr = 0.4;
	/* ingestion */
	this.ing = 0.25;
	/* assimilation */
	this.as = 0.25;
	/* general purpose "info" field */
	this.i = "";

	if (value.length > 0) {
		var position = "0";

		var tmp = value.split(":");
		var data = tmp[1];

		if (tmp.length > 2) // if there was more ":"
			for (i = 2; i < tmp.length; i++)
				data += ":" + tmp[i];

		var info = data.split(",");

		for (var i = 0; i < info.length; i++) {
			var str = info[i];
			if (str.indexOf("\"") > -1) {
				while ((str.split("\"").length % 2) == 1)
					str += "," + info[++i];
			}

			str = str.trim();

			if (str == "")
				position = nextPart(position);
			else {
				var value;

				if ((str.indexOf("\"") > 1 || str.indexOf("\"") == -1)
						&& str.indexOf("=") > -1) {
					position = str.split("=")[0];
					value = str.split("=")[1];
				} else {
					position = nextPart(position);
					value = str;
				}
				
				switch (position) {
				case 'x':
					this.x = parseFloat(value);
					break;
				case 'y':
					this.y = parseFloat(value);
					break;
				case 'z':
					this.z = parseFloat(value);
					break;
				case 'rx':
					this.rx = parseFloat(value);
					break;
				case 'ry':
					this.ry = parseFloat(value);
					break;
				case 'rz':
					this.rz = parseFloat(value);
					break;
				case 'm':
					this.m = parseFloat(value);
					break;
				case 's':
					this.s = parseFloat(value);
					break;
				case 'dn':
					this.dn = value;
					break;
				case 'fr':
					this.fr = value;
					break;
				case 'ing':
					this.ing = value;
					break;
				case 'as':
					this.as = value;
					break;
				case 'i':
					this.i = value;
					break;
				default:
					alert("error");
				}
			}
		}
		
		var latitudeBands = 20;
	    var longitudeBands = 20;
	    var radius = 2;

	    var vertexPositionData = [];
	    var normalData = [];
	    var textureCoordData = [];
	    for (var latNumber = 0; latNumber <= latitudeBands; latNumber++) {
	      var theta = latNumber * Math.PI / latitudeBands;
	      var sinTheta = Math.sin(theta);
	      var cosTheta = Math.cos(theta);

	      for (var longNumber = 0; longNumber <= longitudeBands; longNumber++) {
	        var phi = longNumber * 2 * Math.PI / longitudeBands;
	        var sinPhi = Math.sin(phi);
	        var cosPhi = Math.cos(phi);

	        var x = cosPhi * sinTheta;
	        var y = cosTheta;
	        var z = sinPhi * sinTheta;
	        var u = 1 - (longNumber / longitudeBands);
	        var v = 1 - (latNumber / latitudeBands);

	        normalData.push(x);
	        normalData.push(y);
	        normalData.push(z);
	        textureCoordData.push(u);
	        textureCoordData.push(v);
	        vertexPositionData.push(radius * x);
	        vertexPositionData.push(radius * y);
	        vertexPositionData.push(radius * z);
	      }
	    }


	    var indexData = [];
	    for (var latNumber = 0; latNumber < latitudeBands; latNumber++) {
	      for (var longNumber = 0; longNumber < longitudeBands; longNumber++) {
	        var first = (latNumber * (longitudeBands + 1)) + longNumber;
	        var second = first + longitudeBands + 1;
	        indexData.push(first);
	        indexData.push(second);
	        indexData.push(first + 1);

	        indexData.push(second);
	        indexData.push(second + 1);
	        indexData.push(first + 1);
	      }
	    }

	    moonVertexPositionBuffer = gl.createBuffer();
	    gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
	    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertexPositionData), gl.STATIC_DRAW);
	    this.vertexBuffer.itemSize = 3;
	    this.vertexBuffer.numItems = vertexPositionData.length / 3;

	    
	    gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
	    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(normalData), gl.STATIC_DRAW);
	    this.normalBuffer.itemSize = 3;
	    this.normalBuffer.numItems = normalData.length / 3;
	  
	    gl.bindBuffer(gl.ARRAY_BUFFER, this.colorsBuffer);
	    var colors = [
	      [0.5, 1.0, 0.5, 1.0],     // Front face
	    ];
	    var unpackedColors = [];
	    for (var i = 0; i < normalData.length / 3; i++) {
	      var color = colors[0];
	      for (var j = 0; j < 4; j++) {
	        unpackedColors = unpackedColors.concat(color);
	      }
	    }
	    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(unpackedColors), gl.STATIC_DRAW);
	    this.colorsBuffer.itemSize = 4;
	    this.colorsBuffer.numItems = normalData.length / 3;

	    
	    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
	    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData), gl.STREAM_DRAW);
	    this.indexBuffer.itemSize = 1;
	    this.indexBuffer.numItems = indexData.length;
		
	}
	
	
}